package demo.collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.Vector;

public class DemoList {
	private ArrayList<Integer> alDemo = new ArrayList<Integer>();
	private LinkedList<Integer> llDemo = new LinkedList<Integer>();
	private Vector<Integer> vtDemo = new Vector<Integer>();

	public static void main(String[] args) {
		int length = 500000;
		DemoList demoList = new DemoList();
		demoList.init(length);
		demoList.sortList(demoList.alDemo);
		demoList.sortList(demoList.llDemo);
		demoList.sortList(demoList.vtDemo);

	}

	private void init(int length) {
		Random r = new Random();
		for (int i = 0; i < length; i++) {
			int a = r.nextInt();
			alDemo.add(a);
			llDemo.add(a);
			vtDemo.add(a);
		}
	}

	private void sortList(List<Integer> lst) {
		long start = System.currentTimeMillis();
		Collections.sort(lst, new Comparator<Integer>() {

			@Override
			public int compare(Integer o1, Integer o2) {
				if (o1 < o2) {
					return 1;
				} else if (o1 > o2) {
					return -1;
				}
				return 0;
			}

		});
		long end = System.currentTimeMillis();
//		for (int i = 0; i < lst.size(); i++) {
//			int a = lst.get(i);
//			System.out.print(" " + a);
//		}
		System.out.println("");
		System.out.println("Thoi gian: " + (end - start));
		System.out.println("========================");
//		lst.clear();
	}

}
